<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单号" prop="no">
        <el-input
          v-model="queryParams.no"
          placeholder="请输入单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="手机号" prop="phone">-->
<!--        <el-input-->
<!--          v-model="queryParams.phone"-->
<!--          placeholder="请输入手机号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['yipaiju:demand_order:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['yipaiju:demand_order:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['yipaiju:demand_order:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['yipaiju:demand_order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="demand_orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="id" align="center" prop="id" />-->
      <el-table-column label="单号" align="center" prop="no" />
<!--      <el-table-column label="用户id" align="center" prop="client" />-->
      <el-table-column label="客户名称" align="center" prop="clientName" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="服务时间" align="center" prop="servingTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.servingTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="完成时间" align="center" prop="finishTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.finishTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="推荐人" align="center" prop="recommender" />
<!--      <el-table-column label="状态" align="center" prop="status">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.fo_assets_booking_order_status" :value="scope.row.status"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="状态" align="center" prop="stage">-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.fo_assets_booking_order_stage" :value="scope.row.stage"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="预算价格" align="center" prop="totalBudgetPriceYuan" />
      <el-table-column label="面积 " align="center" prop="houseArea" />
<!--      <el-table-column label="采购原因" align="center" prop="purchaseReason" />-->
<!--      <el-table-column label="省" align="center" prop="province" />-->
<!--      <el-table-column label="市" align="center" prop="city" />-->
<!--      <el-table-column label="区" align="center" prop="district" />-->
<!--      <el-table-column label="卧室" align="center" prop="bedroom" />-->
<!--      <el-table-column label="客厅" align="center" prop="livingroom" />-->
<!--      <el-table-column label="厕所" align="center" prop="toilet" />-->
<!--      <el-table-column label="厨房" align="center" prop="kitchen" />-->
<!--      <el-table-column label="阳台" align="center" prop="balcony" />-->
      <el-table-column label="打星" align="center" prop="rate" />
      <el-table-column label="评论" align="center" prop="comment" />
<!--      <el-table-column label="merchant" align="center" prop="merchant" />-->
<!--      <el-table-column label="完成状态" align="center" prop="finished" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['yipaiju:demand_order:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['yipaiju:demand_order:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改好房订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="单号" prop="no">
              <el-input v-model="form.no" placeholder="请输入单号" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户名称" prop="clientName">
              <el-input v-model="form.clientName" placeholder="请输入客户名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="手机号" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入手机号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="服务时间" prop="servingTime">
              <el-date-picker clearable
                              v-model="form.servingTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择服务时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="完成时间" prop="finishTime">
              <el-date-picker clearable
                              v-model="form.finishTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择完成时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="推荐人" prop="recommender">
              <el-input v-model="form.recommender" placeholder="请输入推荐人" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="预算价格" prop="totalBudgetPriceYuan">
              <el-input v-model="form.totalBudgetPriceYuan" placeholder="请输入预算价格" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="面积" prop="houseArea">
              <el-input v-model="form.houseArea" placeholder="请输入面积" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="采购原因" prop="purchaseReason">
              <el-input v-model="form.purchaseReason" placeholder="请输入采购原因" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="省" prop="province">
              <el-input v-model="form.province" placeholder="请输入省" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="市" prop="city">
              <el-input v-model="form.city" placeholder="请输入市" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="区" prop="district">
              <el-input v-model="form.district" placeholder="请输入区" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="卧室" prop="bedroom">
              <el-input v-model="form.bedroom" placeholder="请输入卧室" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客厅" prop="livingroom">
              <el-input v-model="form.livingroom" placeholder="请输入客厅" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="厕所" prop="toilet">
              <el-input v-model="form.toilet" placeholder="请输入厕所" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="厨房" prop="kitchen">
              <el-input v-model="form.kitchen" placeholder="请输入厨房" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="阳台" prop="balcony">
              <el-input v-model="form.balcony" placeholder="请输入阳台" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="打星" prop="rate">
              <el-input v-model="form.rate" placeholder="请输入打星" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="评论" prop="comment">
              <el-input v-model="form.comment" placeholder="请输入评论" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" prop="stage">
              <el-select v-model="form.stage" placeholder="请选择状态">
                <el-option
                  v-for="dict in dict.type.fo_assets_booking_order_stage"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

<!--        <el-form-item label="用户id" prop="client">-->
<!--          <el-input v-model="form.client" placeholder="请输入用户id" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="merchant" prop="merchant">-->
<!--          <el-input v-model="form.merchant" placeholder="请输入merchant" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="完成状态" prop="finished">-->
<!--          <el-input v-model="form.finished" placeholder="请输入完成状态" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDemand_order, getDemand_order, delDemand_order, addDemand_order, updateDemand_order } from "@/api/yipaiju/demand_order";

export default {
  name: "Demand_order",
  dicts: ['fo_assets_booking_order_stage', 'fo_assets_booking_order_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 好房订单表格数据
      demand_orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        no: null,
        client: null,
        clientName: null,
        phone: null,
        servingTime: null,
        finishTime: null,
        recommender: null,
        status: null,
        stage: null,
        totalBudgetPriceYuan: null,
        houseArea: null,
        purchaseReason: null,
        province: null,
        city: null,
        district: null,
        bedroom: null,
        livingroom: null,
        toilet: null,
        kitchen: null,
        balcony: null,
        rate: null,
        comment: null,
        merchant: null,
        finished: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询好房订单列表 */
    getList() {
      this.loading = true;
      listDemand_order(this.queryParams).then(response => {
        this.demand_orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        no: null,
        client: null,
        clientName: null,
        phone: null,
        createTime: null,
        servingTime: null,
        finishTime: null,
        recommender: null,
        status: null,
        stage: null,
        totalBudgetPriceYuan: null,
        houseArea: null,
        purchaseReason: null,
        province: null,
        city: null,
        district: null,
        bedroom: null,
        livingroom: null,
        toilet: null,
        kitchen: null,
        balcony: null,
        rate: null,
        comment: null,
        merchant: null,
        finished: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加好房订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDemand_order(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改好房订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDemand_order(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDemand_order(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除好房订单编号为"' + ids + '"的数据项？').then(function() {
        return delDemand_order(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('yipaiju/demand_order/export', {
        ...this.queryParams
      }, `demand_order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
